import spock.lang.Specification

/**
 * 三个元素的栈
 *
 * Created by houjinxin on 17-3-31.
 */
class StackWithThreeElementsSpec extends Specification{
    def stack = new Stack()

    def setup() {
        ['test1', 'test2', 'test3'].each { it ->
            stack.push(it)
        }
    }

    def "size"() {
        expect: stack.size() == 3
    }

    def "pop"() {
        when:
        def x = stack.pop()
        then:
        x == 'test3'
        stack.size() == 2
    }

    def "peek"() {
        when:
        def x = stack.peek()
        then:
        x == 'test3'
        stack.size() == 3
    }

    def "push"(){
        when:
        stack.push("test4")
        then:
        stack.size() == 4
        stack.peek() == 'test4'
    }
}
